﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8" />
    <title>Krajee JQuery Plugins - &copy; Kartik</title>
    <link href="~/Resources/mainFrame/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Resources/mainFrame/css/plugins/bootstrap-fileinput/fileinput.min.css" rel="stylesheet" />
    <link href="~/Resources/mainFrame/css/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
    <script src="~/Resources/mainFrame/js/plugins/layer/laydate/laydate.js"></script>
    <script src="~/Resources/mainFrame/js/jquery.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/bootstrap-fileinput/fileinput.js"></script>
    <script src="~/Resources/mainFrame/js/bootstrap.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/bootstrap-fileinput/fileinput_locale_zh.js"></script>
    <script src="~/Resources/tools/jquery-hcq2-extend.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/select/bootstrap-select.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/validate/messages_zh.min.js"></script>
    <script src="~/Resources/mainFrame/js/demo/form-validate-demo.min.js"></script>
    <style>
        .fileClass label{
            text-align:right;
        }
       .col-sm-7{
           margin-bottom:8px;
        }
       #doc_type_sel{
           border:1px solid #CCCCCC;
           display:none;
           position:absolute;
           z-index:90;
           width:93%;
           background-color:#fff;
       }
       #doc_type_sel li:hover{
           background-color:#CCCCCC;
           cursor:pointer;
       }
       #doc_type_sel li{
           list-style-type:none;
           margin-left:-40px;
           padding-left:5px;
       }
    </style>
</head>
<body onclick="closeType()">
    <div class="container kv-main">
        <form class="form-horizontal m-t" id="orgFormTable" method="post" enctype="multipart/form-data">
            <div class="fileClass" style="height:280px;">
                <div class="form-group">
                    <label class="col-sm-3 control-label">编号<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <input id="folder_num" name="folder_num" type="text"  required="" aria-required="true" class="form-control input-sm" placeholder="录入编号" title="录入编号" />
                        <!-- 素材类型 -->
                        <input type="hidden" id="doc_type" name="doc_type" value="" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">@ViewBag.pageName 名称<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <input id="file_name" name="file_name" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="默认读取上传素材名" title="默认读取上传素材名" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">@ViewBag.pageName 别名：</label>
                    <div class="col-sm-7">
                        <input id="alias_name" name="alias_name" type="text" class="form-control input-sm" placeholder="默认读取上传素材名" title="默认读取上传素材名" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">作者<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <input id="folder_author" name="folder_author" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="请输入作者" title="请输入作者" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">联系电话<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <input id="folder_phone" name="folder_phone" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="请输入联系电话" title="请输入联系电话" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">发布开始时间：</label>
                    <div class="col-sm-7">
                        <input id="issue_start" name="issue_start" type="text" class="form-control laydate-icon" placeholder="请输入发布开始时间">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">@ViewBag.pageName 类型<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <select id="file_classify" name="file_classify" title="请选择素材类型" class="form-control input-sm selectcontrol" data-live-search="true" required="" aria-required="true" placeholder="请选择素材类型"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">@ViewBag.pageName 来源：</label>
                    <div class="col-sm-7">
                        <select id="folder_source" name="folder_source" title="请选择素材来源" class="form-control input-sm selectcontrol" placeholder="请选择素材来源"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">@ViewBag.pageName 定价<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <input id="file_money" name="file_money" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="请给素材标价" title="请给素材标价" />
                    </div>
                </div>      
                <div class="form-group">
                    <label class="col-sm-3 control-label">供应商<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <select id="supplier" name="supplier" title="请选择供应商" class="form-control input-sm selectcontrol" placeholder="请选择供应商" style="padding: 5px 10px;" required="" aria-required="true"></select>
                    </div>
                </div>       
                <div class="form-group">
                    <label class="col-sm-3 control-label">权限<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <select id="folder_limit" name="folder_limit" title="请选择权限" class="form-control input-sm selectcontrol" placeholder="请选择权限" style="padding: 5px 10px;" required="" aria-required="true">
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">@ViewBag.pageName 属性<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <select id="file_status" name="file_status" title="请选择素材属性" class="form-control input-sm selectcontrol" placeholder="请选择素材属性" style="padding: 5px 10px;" required="" aria-required="true">
                            <option value="0" selected>私有</option>
                            <option value="1">公开</option>
                        </select>
                    </div>
                </div>
                @*<div class="form-group">
                    <label class="col-sm-3 control-label">文号<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <input id="doc_number" name="doc_number" type="text" class="form-control laydate-icon" placeholder="请输入文号" required="" aria-required="true"/>
                    </div>
                </div>*@
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-7">
                        <textarea class="form-control" id="file_note" name="file_note" rows="3" placeholder="请输入备注信息" title="请输入备注信息"></textarea>
                    </div>
                </div>
            </div>
            <div class="fileClass" style="height:300px;display:none;">
                <div class="form-group">
                    <label class="col-sm-3 control-label">@ViewBag.pageName 附件<span id="fileTitle" class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-7">
                        <input id="fileUpload" type="file" multiple class="file" required="" aria-required="true"/>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <script>
        var folder_id = $.getUrls("folder_id"),//节点ID
            doc_name = $.getUrls("doc_name"),//素材类型（前一个页面传递）
        file_id = $.getUrls("file_id"),//素材ID
        page_type = "@ViewBag.page_type",//页面类型
        rest_type = "@ViewBag.rest_type",
        read = $.getUrls("read"),//是否只读
        fileExtension = [];
        if (doc_name) {
            doc_name = decodeURI(doc_name);
            if (doc_name.indexOf("(") > -1)
                doc_name = doc_name.substring(0, doc_name.indexOf("("));
        }
        if (rest_type) {
            rest_type = rest_type.split(',');  //[rest_type.replace(new RegExp(",", "gm"), ",")];
            $.each(rest_type, function (index, item) {
                fileExtension.push(item);
            });
        }  
        var $url = '/DocManager/UpLoadFile/' + folder_id, isUpload = 0;//0 ：不上传，1：上传
        if (file_id)
            $url = '/DocManager/EditLoadFile/' + file_id;//EditLoadFile
        $("#fileUpload").fileinput({
            uploadUrl: $.ctx() + $url, //上传的地址
            allowedFileExtensions: fileExtension,//['FBX', '3DS', 'ASC', 'AI', 'ASE', 'DAE', 'DWF', 'DWG', 'DXF', 'FLT', 'HTR', 'IGS', 'OBJ', 'PXPROJ', 'SAT', 'STL', 'W3D', 'WRL'],//允许上传格式
            overwriteInitial: false,
            showUpload: false,//是否显示上传按钮
            maxFileSize: 0,//20M以内
            maxFileCount: 1,
            minFileCount: 1,
            uploadExtraData: function () {
                var dataJson = {}, obj = $('#orgFormTable').serializeArray();
                $.each(obj, function (i, v) {
                    dataJson[v.name] = v.value;
                });
                dataJson["isUpload"] = isUpload;
                return dataJson;
            },
            slugCallback: function (filename) {
                return filename.replace('(', '_').replace(']', '_');
            }
        }).on('fileuploaded', function (event, data, previewId, index) {
            window.parent.docManager.closeUpLoadForm(data.response);
        }).on('filebatchselected', function (event, files) {
            //选中文件后
            isUpload = 1;
        });
        //初始化页面
        function initPage() {
            if (read) {
                $('#orgFormTable').find("input[type='text']").attr("disabled", true);
                $('#orgFormTable').find("select").attr("disabled", true);
                $('#orgFormTable').find("textarea").attr("disabled", true);
            }
        }
        //文件上传方法
        function initData() {
            var dateStart = {
                elem: '#issue_start',
                format: 'YYYY-MM-DD',
                max: '2099-06-16 23:59:59', //最大日期
                istime: true,
                istoday: false,
                choose: function (datas) {
                    dateEnd.min = datas; //开始日选好后，重置结束日的最小日期
                    dateEnd.start = datas; //将结束日的初始值设定为开始日
                }
            };
            //var dateEnd = {
            //    elem: '#issue_end',
            //    format: 'YYYY-MM-DD',
            //    min: laydate.now(),
            //    max: '2099-06-16 23:59:59',
            //    istime: true,
            //    istoday: false,
            //    choose: function (datas) {
            //        dateStart.max = datas; //结束日选好后，重置开始日的最大日期
            //    }
            //};
            laydate(dateStart);
            //laydate(dateEnd);
            $('#issue_start').val(laydate.now().substring(0, 4) + '-01-01');
        }
        var doc_type_data = null;
        function initSelect() {
            $('#file_classify').initSelectcontrol("docClassify");
            $('#folder_source').initSelectcontrol("docSource");
            $('#folder_limit').initSelectcontrol("docLimits");
            $('#supplier').initSelectcontrol("docSupplier");
        }
        function initEdit() {
            if (!file_id) {
                $.ajax({
                    type: 'post',
                    url: ctx + '/DocManager/GetNodeNum',
                    data:{page_type:page_type},
                    dataType: 'json',
                    async: false,
                    success: function (data) {
                        if (data.Statu === 0) {
                            //添加
                            var num = 0, path, d = "";
                            if (data.Data)
                                num = parseInt(data.Data);
                            num += 1;
                            switch (num.toString().length) {
                                case 1: path = "000" + num.toString(); break;
                                case 2: path = "00" + num.toString(); break;
                                case 3: path = "0" + num.toString(); break;
                            }
                            //是否是3D
                            if (doc_name && doc_name.toLowerCase().indexOf('d') > -1)
                                d = "D";
                            //默认时间
                            var date = new Date();
                            var year = date.getFullYear().toString(), month = date.getMonth() + 1, day = date.getDate();
                            if (month <= 9)
                                month = "0" + month.toString();
                            if (day <= 9)
                                day = "0" + day.toString();
                            if (page_type === "VRManager")
                                $('#folder_num').val("LZSC" + year + month + day + path + d);
                            else if (page_type === "VRWorks")
                                $('#folder_num').val("LZZP" + year + month + day + path + d);
                            else
                                $('#folder_num').val(year + month + day + path + d);
                        }
                    }
                });
                return false;
            }
            $.ajax({
                type: 'post',
                url: ctx + '/DocManager/GetNodeDataById/' + file_id,
                dataType: 'json',
                data:{page_type:page_type},
                async: false,
                success: function (data) {
                    if (data.Statu === 0) {
                        //填充数据
                        var row = data.Data;
                        if (row) {
                            if (row.issue_start != null && row.issue_start.length > 10)
                                row.issue_start = $.formatDate(new Date(parseInt(row.issue_start.slice(6))));
                            $('#orgFormTable')[0].reset();//重置表单
                            $('#orgFormTable').LoadForm(row);//表单填充数据
                            //编辑模式情况文件上传必填
                            $('#fileTitle').remove();
                            $('#fileUpload').removeAttr("required").removeAttr("aria-required");
                        }
                    }
                    else
                        layer.msg(data.Msg, { icon: 5 });
                }
            });
        }
        //保存上传数据
        function upLoadDoc() {
            //判断字段是否合法
            if (!$('#orgFormTable').valid()) return false;
            //判断素材类型是否合法
            $('#doc_type').val(doc_name);
            if (isUpload > 0)
                $("#fileUpload").fileinput("upload");//上传
            else {
                var dataJson = {}, obj = $('#orgFormTable').serializeArray();
                $.each(obj, function (i, v) {
                    dataJson[v.name] = v.value;
                });
                dataJson["isUpload"] = isUpload;
                $.ajax({
                    type: 'post',
                    url: $.ctx() + $url,
                    dataType: 'json',
                    data: dataJson,
                    async: false,
                    success: function (data) {
                        if (data.Statu === 0)
                            window.parent.docManager.closeUpLoadForm(data);
                        else
                            layer.msg(data.Msg, { icon: 5 });
                    }
                });
            }
        }
        function closeType() {
            $('#doc_type_sel').css('display', 'none');
        }
        $(function () {
            initPage();
            initData();
            initSelect();
            initEdit();
        });
    </script>
</body>
</html>